package validator;

import exceptions.InvalidPasswordException;
import exceptions.RequiredPasswordMissingException;

/**
 * Implements a validator of passwords
 * @author Alexandre, Cristovao, Raul, Rodolpho, Tales
 * @version 1.1
 * @milestone Number 2
 */
public class PasswordValidator {

	/**
	 * Checks if the user typed something
	 * @param password
	 * @throws RequiredPasswordMissingException
	 */
	public static void checkMissing(String password)
			throws RequiredPasswordMissingException {
		if (password.trim() == "" || password == null) {
			throw new RequiredPasswordMissingException(
					"Senha eh um dado obrigatorio.");

		}
	}

	/**
	 * Validates a password
	 * @param password
	 * @throws InvalidPasswordException
	 */
	public static void validatePassword(String password)
			throws InvalidPasswordException {
		if (password == null || password.length() < 6) {
			throw new InvalidPasswordException(
					"Senha deve ter no minimo 6 caracteres.");
		}
	}

	/**
	 * Check if the password is valid
	 * @param password
	 * @throws RequiredPasswordMissingException
	 * @throws InvalidPasswordException
	 */
	public static void checkAndValidatePassword(String password)
			throws RequiredPasswordMissingException, InvalidPasswordException {
		checkMissing(password);
		validatePassword(password);
	}

}
